package ferp.android.dialogs;

import android.content.Context;
import android.content.DialogInterface;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import ferp.android.GUI;
import ferp.android.R;

/**
 * User: olegs
 * Date: 30/05/12 14:18
 */
public class ErrorDialog extends Dialog
{
  public interface Listener
  {
    void onCloseClick();
  }

  public ErrorDialog(final Context context, final Listener listener)
  {
    this(context, listener, R.string.sorry_internal_error_occurred);
  }

  public ErrorDialog(Context context, final Listener listener, int resMsg)
  {
    super(context, R.layout.dialog_error, R.string.error);

    setCancelable(false);

    close = resolveButton(R.id.dlg_element_footer_button, R.string.close);

    TextView message = (TextView)findViewById(R.id.dlg_error_text);

    message.setText(resMsg);
    message.setTypeface(GUI.Font.BOLD);

    close.setOnClickListener(new View.OnClickListener()
    {
      public void onClick(View view)
      {
        if (view.isClickable())
        {
          view.setClickable(false);

          dismiss();
          listener.onCloseClick();
        }
      }
    });

    setOnShowListener(new OnShowListener()
    {
      @Override
      public void onShow(DialogInterface dialogInterface)
      {
        close.setClickable(true);
      }
    });
  }

  private final Button close;
}
